import request from '@/utils/request'

// 生产入库单相关API

// 获取生产入库单列表 (wm_product_in_stock)
export function getProductInStockList(query) {
  return request({
    url: '/mes/productInStock/list',
    method: 'get',
    params: query
  })
}

// 获取生产入库单详细信息 (wm_product_in_stock)
export function getProductInStock(id) {
  return request({
    url: '/mes/productInStock/' + id,
    method: 'get'
  })
}

// 新增生产入库单 (wm_product_in_stock)
export function addProductInStock(data) {
  return request({
    url: '/mes/productInStock',
    method: 'post',
    data: data
  })
}

// 修改生产入库单 (wm_product_in_stock)
export function updateProductInStock(data) {
  return request({
    url: '/mes/productInStock',
    method: 'put',
    data: data
  })
}

// 删除生产入库单 (wm_product_in_stock)
export function delProductInStock(id) {
  return request({
    url: '/mes/productInStock/' + id,
    method: 'delete'
  })
}

// 获取生产入库单明细列表 (wm_product_in_stock_detail)
export function getProductInStockDetailList(query) {
  return request({
    url: '/mes/productInStockDetail/list',
    method: 'get',
    params: query
  })
}

// 新增生产入库单明细 (wm_product_in_stock_detail)
export function addProductInStockDetail(data) {
  return request({
    url: '/mes/productInStockDetail',
    method: 'post',
    data: data
  })
}

// 批量新增生产入库单明细 (wm_product_in_stock_detail)
export function batchAddProductInStockDetail(data) {
  return request({
    url: '/mes/productInStockDetail/batch',
    method: 'post',
    data: data
  })
}

// 提交生产入库单
export function submitProductRecpt(id) {
  return request({
    url: '/mes/productrecpt/submit/' + id,
    method: 'put'
  })
}

// 审核生产入库单
export function auditProductRecpt(data) {
  return request({
    url: '/mes/productrecpt/audit',
    method: 'put',
    data: data
  })
}

// 获取生产入库单统计信息
export function getProductRecptStats(query) {
  return request({
    url: '/mes/productrecpt/stats',
    method: 'get',
    params: query
  })
}

// 根据SN码获取入库单信息 (包含表头和表体)
export function getInStockBySnCode(snCode) {
  return request({
    url: '/mobile/wm/stock/getInStockBySnCode/' + snCode,
    method: 'get'
  })
}

// 根据SN码获取入库单明细信息
export function getInStockDetailBySnCode(snCode) {
  return request({
    url: '/mobile/wm/stock/getInStockDetailBySnCode/' + snCode,
    method: 'get'
  })
}

// 扫码入库操作
export function scanInStock(snCode) {
  return request({
    url: '/mobile/wm/stock/scanInStock/' + snCode,
    method: 'post'
  })
}

// 兼容旧接口 - 扫码获取物料信息
export function getMaterialByBarcode(barcode) {
  return request({
    url: '/mes/productInStock/material/' + barcode,
    method: 'get'
  })
}

// 兼容旧接口 - 根据SN获取物料信息
export function getMaterialBySn(sn) {
  return request({
    url: '/mes/productInStock/material/sn/' + sn,
    method: 'get'
  })
}

// 根据入库单ID获取明细列表
export function getInStockDetailsByInStockId(inStockId) {
  return request({
    url: '/mes/productInStockDetail/inStock/' + inStockId,
    method: 'get'
  })
}

// 获取仓库列表
export function getWarehouseList() {
  return request({
    url: '/mes/warehouse/list',
    method: 'get'
  })
}

// 获取物料列表
export function getMaterialList(query) {
  return request({
    url: '/mes/item/list',
    method: 'get',
    params: query
  })
}

// ==================== 出库相关API ====================

// 获取销售出库单列表 (wm_product_sales)
export function getProductSalesList(query) {
  return request({
    url: '/mes/productSales/list',
    method: 'get',
    params: query
  })
}

// 获取销售出库单详细信息 (wm_product_sales)
export function getProductSales(id) {
  return request({
    url: '/mes/productSales/' + id,
    method: 'get'
  })
}

// 新增销售出库单 (wm_product_sales)
export function addProductSales(data) {
  return request({
    url: '/mes/productSales',
    method: 'post',
    data: data
  })
}

// 修改销售出库单 (wm_product_sales)
export function updateProductSales(data) {
  return request({
    url: '/mes/productSales',
    method: 'put',
    data: data
  })
}

// 删除销售出库单 (wm_product_sales)
export function delProductSales(id) {
  return request({
    url: '/mes/productSales/' + id,
    method: 'delete'
  })
}

// 获取产品销售出库记录明细列表 (wm_product_sales_detail)
export function getProductSalesDetailList(query) {
  return request({
    url: '/mes/productSalesDetail/list',
    method: 'get',
    params: query
  })
}

// 新增产品销售出库记录明细 (wm_product_sales_detail)
export function addProductSalesDetail(data) {
  return request({
    url: '/mes/productSalesDetail',
    method: 'post',
    data: data
  })
}

// 批量新增产品销售出库记录明细 (wm_product_sales_detail)
export function batchAddProductSalesDetail(data) {
  return request({
    url: '/mes/productSalesDetail/batch',
    method: 'post',
    data: data
  })
}

// 获取产品销售出库行列表 (wm_product_sales_line)
export function getProductSalesLineList(query) {
  return request({
    url: '/mes/productSalesLine/list',
    method: 'get',
    params: query
  })
}

// 新增产品销售出库行 (wm_product_sales_line)
export function addProductSalesLine(data) {
  return request({
    url: '/mes/productSalesLine',
    method: 'post',
    data: data
  })
}

// 批量新增产品销售出库行 (wm_product_sales_line)
export function batchAddProductSalesLine(data) {
  return request({
    url: '/mes/productSalesLine/batch',
    method: 'post',
    data: data
  })
}

// 根据SN码获取出库单信息 (包含所有行)
export function getOutboundBySnCode(snCode) {
  return request({
    url: '/mobile/wm/productsales/getOutboundBySnCode/' + snCode,
    method: 'get'
  })
}

// 根据出库单号获取出库单信息 (包含所有行)
export function getOutboundBySalesCode(salesCode) {
  return request({
    url: '/mobile/wm/productsales/getOutboundBySalesCode/' + salesCode,
    method: 'get'
  })
}

// 扫码出库确认操作
export function scanOutboundConfirm(snCode) {
  return request({
    url: '/mobile/wm/productsales/scanOutboundConfirm/' + snCode,
    method: 'post'
  })
}

// 提交出库
export function submitOutbound(data) {
  return request({
    url: '/mobile/wm/sales/submitOutbound',
    method: 'post',
    data: data
  })
}

// 带运单号提交出库
export function submitOutboundWithShipping(data) {
  return request({
    url: '/mobile/wm/sales/submitOutboundWithShipping',
    method: 'post',
    data: data
  })
}

// 根据出库单明细ID获取SN明细
export function getSnDetailsByOutboundDetailId(outboundDetailId) {
  return request({
    url: '/mobile/wm/sales/getSnDetailsByOutboundDetailId/' + outboundDetailId,
    method: 'get'
  })
}

// 批量提交出库
export function batchSubmitOutbound(data) {
  return request({
    url: '/mobile/wm/sales/batchSubmitOutbound',
    method: 'post',
    data: data
  })
}

// 获取今日出库统计
export function getTodayOutboundStats() {
  return request({
    url: '/mobile/wm/sales/getTodayOutboundStats',
    method: 'get'
  })
}

// 执行出库操作
export function executeOutbound(salesId) {
  return request({
    url: '/mes/wm/productsales/' + salesId,
    method: 'put'
  })
}

// 根据SN码获取入库单信息
export function getInboundBySnCode(snCode) {
  return request({
    url: '/mobile/wm/productrecpt/getInboundBySnCode/' + snCode,
    method: 'get'
  })
}

// 根据入库单号获取入库单信息
export function getInboundByRecptCode(recptCode) {
  return request({
    url: '/mobile/wm/productrecpt/getInboundByRecptCode/' + recptCode,
    method: 'get'
  })
}

// 扫码入库确认操作
export function scanInboundConfirm(snCode) {
  return request({
    url: '/mobile/wm/productrecpt/scanInboundConfirm/' + snCode,
    method: 'post'
  })
}

// 执行入库操作
export function executeInbound(recptId) {
  return request({
    url: '/mes/wm/productrecpt/' + recptId,
    method: 'put'
  })
}

// 确认SN明细信息（仓位、备注，确认信息后台动添加）
export function confirmSnDetail(data) {
  return request({
    url: '/mobile/wm/productrecpt/confirmSnDetail',
    method: 'put',
    data: data
  })
}

// ==================== 移动端 · 预入库/上架 流程API ====================

// 扫码仅创建入库单与一条入库行（不上架）
export function createInboundBySn(data) {
  return request({
    url: '/mobile/wm/productrecpt/createBySn',
    method: 'post',
    data: data
  })
}

// 扫码创建并立即上架（可在请求体中附带仓位信息）
export function createInboundBySnAndPutaway(data) {
  return request({
    url: '/mobile/wm/productrecpt/createBySnAndPutaway',
    method: 'post',
    data: data
  })
}

// 对整张入库单执行上架（前置：明细带好仓位）
export function putawayInbound(recptId) {
  return request({
    url: '/mobile/wm/productrecpt/' + recptId,
    method: 'put'
  })
}

// 执行上架动作（推荐方式）
export function executePutaway(data) {
  return request({
    url: '/mobile/wm/productrecpt/executePutaway',
    method: 'post',
    data: data
  })
}

// 分页查询已确认的入库明细记录
export function getConfirmDetail(query) {
  return request({
    url: '/mobile/wm/productrecpt/getConfirmDetail',
    method: 'get',
    params: query
  })
}